<title>商家提现</title>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="financial-seller_withdraw-index-search_from">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="username" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <script type="text/html" template lay-url="{{ layui.setter.apiHost }}/financial/seller_withdraw/get_status" lay-done="layui.form.render();">
                            <select name="status">
                                <option value=""></option>
                                {{# layui.each(d.data, function(index, item){ }}
                                <option value="{{ index }}">{{ item }}</option>
                                {{# }); }}
                            </select>
                        </script>
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="financial-seller_withdraw-index-search_button">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="financial-seller_withdraw-index" lay-filter="financial-seller_withdraw-index"></table>
            <script type="text/html" id="financial-seller_withdraw-index-action_button">
                {{# if(d.status == 0){ }}
                <a class="layui-btn layui-btn-xs" lay-event="financial-seller_withdraw-index-agreed">同意</a>
                <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="financial-seller_withdraw-index-refused_money">拒绝并退还资金</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="financial-seller_withdraw-index-refused_no_money">拒绝不退还资金</a>
                {{# } }}
            </script>
        </div>
    </div>
</div>
<script>
    layui.use(['common', 'table'], function () {
        var $ = layui.jquery,
            common = layui.common,
            view = layui.view,
            table = layui.table,
            form = layui.form,
            lay_id_prefix = 'financial-seller_withdraw-index',//当前页id前缀
            api_action_url = layui.setter.apiHost + '/financial/seller_withdraw';

        //表单搜索
        form.on('submit(' + lay_id_prefix + '-search_button)', function (data) {
            var field = data.field;
            field.page = 1;//默认第一页
            table.reload(lay_id_prefix, {
                where: field
            });
        });

        //表格操作
        table.render({
            elem: '#' + lay_id_prefix,
            url: api_action_url,
            toolbar: '#' + lay_id_prefix + '-toolbar_tmp',
            cols: [[
                {type: 'checkbox', fixed: 'left'},
                {field: 'id', title: 'ID', width: 80},
                {field: 'username', title: '用户名', minWidth: 120},
                {field: 'amount', title: '提现金额', width: 120},
                {field: 'done_at', title: '完成时间', width: 170},
                {field: 'note', title: '备注', width: 150},
                {field: 'created_at', title: '创建时间', width: 170},
                {field: 'status_text', title: '状态', width: 150, fixed: 'right'},
                {title: '操作', width: 300, align: 'center', fixed: 'right', toolbar: '#' + lay_id_prefix + '-action_button'}
            ]],
            page: true
        });

        //监听工具条操作按钮
        table.on('tool(' + lay_id_prefix + ')', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case lay_id_prefix + '-agreed':
                    common.ajax(api_action_url + '/agreed', lay_id_prefix, {id: data.id});
                    break;
                case lay_id_prefix + '-refused_money':
                    layer.prompt({title: '请输入备注', formType: 2}, function (note, index) {
                        common.ajax(api_action_url + '/refused_money', lay_id_prefix, {id: data.id, note: note});
                        layer.close(index);
                    });
                    break;
                case lay_id_prefix + '-refused_no_money':
                    layer.prompt({title: '请输入备注', formType: 2}, function (note, index) {
                        common.ajax(api_action_url + '/refused_no_money', lay_id_prefix, {id: data.id, note: note});
                        layer.close(index);
                    });
                    break;
            }
        });

    });
</script>
